package com.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import java.util.Set;

public class MapTest1 {
	public static void main(String[] args) {
		Map<Integer, String> map = new HashMap<Integer, String>();
		//加入数据key-value
		map.put(1, "张三");
		map.put(2, "李四");
		map.put(3, "王五");
		System.out.println(map);
		
		System.out.println("------------遍历key");
		Set<Integer> keys = map.keySet();
		for(Integer key : keys) {
			System.out.println(key);
		}
		
		System.out.println("------------遍历key");
		Collection<String> values = map.values();
		values.forEach((item)->{
			System.out.println(item);
		});
		
		System.out.println("------------遍历key-value");
		 keys = map.keySet();
		for(Integer key : keys) {
			System.out.println(key+"="+map.get(key));
		}
		
		System.out.println("------------遍历key-value");
		Set<Entry<Integer, String>> set = map.entrySet();
		for(Entry<Integer, String> item : set) {
			System.out.println(item.getKey()+"="+item.getValue());
		}
		System.out.println("------------遍历key-value");
		map.forEach(new BiConsumer<Integer, String>() {

			@Override
			public void accept(Integer t, String u) {
				System.out.println(t+"="+u);
			}
		});
		}
	
}
